﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using System.Data;
using System.Data.SqlClient;

namespace DAO
{
    public class PhieuThuDAO : DataProvider
    {
      
        PhieuThuDTO ptDTO = new PhieuThuDTO();

        public DataTable LayTable()
        {
            string sql = "select maKhachHang,sum(sotien) as TongTienTra from PhieuThu group by MaKhachHang";
            //sql += "where NgayThu = ''";
            SqlConnection con = DataProvider.ConnectDB();
            SqlCommand cmd = new SqlCommand(sql, con);

            SqlDataAdapter adapter = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            adapter.Fill(dt);
            return dt;                      
        }
        public DataTable LayTableTheoThang(string m)
        {
            string sql = "select maKhachHang,sum(sotien) as TongTienTra from PhieuThu where month(ngaythu) = '"+m+"' group by MaKhachHang";
            //sql += "where NgayThu = ''";
            SqlConnection con = DataProvider.ConnectDB();
            SqlCommand cmd = new SqlCommand(sql, con);

            SqlDataAdapter adapter = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            adapter.Fill(dt);
            return dt;
        }
        // việt 
        public DataTable LayTableTheoKH(int MaKH)
        {
            string sql = "select maKhachHang,sotien from PhieuThu  where MaKhachHang = " + MaKH;
            //sql += "where NgayThu = ''";
            SqlConnection con = DataProvider.ConnectDB();
            SqlCommand cmd = new SqlCommand(sql, con);

            SqlDataAdapter adapter = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            adapter.Fill(dt);
            return dt;
        }

    }
}
